package com.util;

import java.security.Security;
import java.util.Properties;

import javax.mail.Address;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class test {

	public static void main(String[] args) throws Exception  {
		
		
		try {
		  
		Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
        final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
		
	        // 发给谁
	        String to = "guowenjie@huahaipharm.com";
	        
	        // 发送者的用户名和密码(邮箱登录用)
	        final String username = "zjypsp@zjcdce.org.cn"; // 此处填写发送的邮箱名
	        final String password = "YHSPZXypspk123456"; // 此处填写登录的邮箱密码
	 
	        // 定义properties对象，设置环境信息
	         Properties props = new Properties();
	          props.setProperty("mail.smtp.host", "smtp.qiye.aliyun.com");
	          props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);
	          props.setProperty("mail.smtp.socketFactory.fallback", "false");
	          props.setProperty("mail.smtp.port", "465");
	          props.setProperty("mail.smtp.socketFactory.port", "465");
	          props.put("mail.smtp.auth", "true");
		       
	        Session session = Session.getDefaultInstance(props, new Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(username, password);
                }
             });
	        // 当设置为true，JavaMail AP就会将其运行过程和邮件服务器的交互命令信息输出到console中，用于JavaMail的调试
	       
	            
	            // 创建邮件对象
	          Message  message = new MimeMessage(session);
	            
	            // 设置邮件发送方
	            message.setFrom(new InternetAddress(username,"药品审评科"));
	            
	            message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to, false));
	            
	
	            
	            // 设置邮件发送的主题<邮件标题> size = '7'
	            message.setSubject("审核情况");
	            String  msg = "<font style='font-family:\"宋体\";' size = '4'  >尊敬的平台用户：</font><br/><font style='font-family:\"宋体\";' size = '4' >&nbsp;&nbsp;您好！</font><br/><font style='font-family:\"宋体\";' size = '4'  >&nbsp;&nbsp;您申请的已上市药品变更类别查询平台账号已通过审核，账号信息如下：</font><br/>";
	            msg = msg + "<font style='font-weight: bold;font-family:\"宋体\";' size = '4' >&nbsp;&nbsp;账号：XXXXXX</font><br/>";
	            msg = msg + "<font style='font-weight: bold;font-family:\"宋体\";' size = '4'  >&nbsp;&nbsp;密码：XXXXXX</font><br/>";
	            msg = msg + "<font style='font-family:\"宋体\";' size = '4' >&nbsp;&nbsp;请及时更改并妥善保管您的账号及密码。</font><br/>";
	            msg = msg + "<br/><font style='font-family:\"宋体\";'  size = '4'>&nbsp;&nbsp;系统邮件，请勿回复。</font><br/>";
	            msg = msg + "<hr />";
	            msg = msg + "<font style='font-weight: bold;font-family:\"宋体\";' size = '4' >&nbsp;&nbsp;浙江省药品化妆品审评中心</font>";
	                    // 设置邮件发送的内容
	            message.setContent(msg,"text/html;charset=utf-8");
	            //Transport transport=session.getTransport();
	            
	          //Transport transport=session.getTransport();
	            
	            // 连接邮件服务器，“”中填写邮件服务器主机名
	           // transport.connect(config.getSmtphost(),25, username, password);
	          //  transport.sendMessage(message,new Address[]{new InternetAddress(to)});
	            Transport.send(message);
	            
	           
	        } catch (MessagingException e) {
	            e.printStackTrace();
	            return;
	        }
		
	}
	
	
}
